<template>
    <div>
        <h1>修改会员</h1>
        <a href="/User">前往查看会员信息</a>
        <table class="table">
            <tbody>
                <tr>
                    <td>会员名称</td>
                    <td>
                        <input type="text" v-model="data.Uname"> 
                    </td>
                </tr>

                <tr>
                    <td>会员年龄</td>
                    <td>
                        <input type="number" v-model="data.Age">
                    </td>
                </tr>

                <tr>
                    <td>会员等级</td>
                    <td>
                        <select v-model="data.Djid">
                            <option value=0>请选择</option>
                            <option v-for="d in dj" :value="d.Did">{{ d.Dname }}</option>
                        </select>
                    </td>
                </tr>

                <tr>
                    <td>头像上传</td>
                    <td>
                        <input type="file" @change="Files">
                        <img :src="'https://localhost:7185/'+data.Img" style="width: 60px;height: 60px;">
                    </td>
                </tr>

                <tr>
                    <td>登录时间</td>
                    <td>
                        <input type="date" v-model="data.Date">
                    </td>
                </tr>

                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" v-model="data.State" name="state" :value="true">启用
                        <input type="radio" v-model="data.State" name="state" :value="false">禁用
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="修改" @click="Upts()">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue';
import axios from 'axios';
import { useInfoStore } from '@/stores/info';
import { useRoute, useRouter } from 'vue-router';
import moment from 'moment';

var info=useInfoStore();
var touer=useRouter();
var toue=useRoute();

//添加的model
const data=ref({
    "Uid": 0,
  "Uname": "",
  "Age": 0,
  "Djid": 0,
  "Img": "string",
  "Date": "2025-04-16T09:43:36.797Z",
  "State": true
})

//等级model
const dj=ref([{
    "Did": 0,
  "Dname": "",
  "State": true,
  "Qyname": ""
}])


//钩子
onMounted(() => {
    glq();
    Djlist();
    Ft();
})

//图片上传
const Files=(a:any)=>{
    var f=a.target.files[0];
    var fd=new FormData();
    fd.append("file",f);
    if(f.type!="image/png" && f.type!="image/jpeg"){
        alert("只能上传jpg 和 png 格式的图片");
        return;
    }
    if(f.size>1024*1024*2){
        alert("最大只能上传2MB的图片");
        return;
    }
    axios.post("https://localhost:7185/api/Files/Files",fd).then(res=>{
        data.value.Img=res.data;
    })
}




//反填
const Ft=()=>{
    axios.get("https://localhost:7185/api/User/Getuserft",{params:{id:toue.query.id}}).then(res=>{
        data.value=res.data;
        data.value.Date=moment(data.value.Date).format('yyyy-MM-DD');
    })
}

const Upts=()=>{
    debugger;
    axios.put("https://localhost:7185/api/User/Uptuse",data.value).then(res=>{
        if(res.data>0){
            alert("修改成功");
            touer.push({path:'/User'})
        }else{
            alert("修改失败");
        }
    })
}









//等级下拉框
const Djlist=()=>{
    axios.get("https://localhost:7185/api/User/GetDJ").then(res=>{
        dj.value=res.data;
    })
}




















//验证是否登录
const glq=()=>{
    if(info.find.name==""){
        alert("请您先登录");
        touer.push({path:"/DL"});
    }
}
</script>

<style scoped>

</style>